package test.ThreadTest;

import java.util.concurrent.*;

/**
 * @Author duWenJian
 * @Date 2024/2/19 13:31
 * @Version 1.0
 */
public class demo02 {
    public static void main(String[] args) {
        ExecutorService service = Executors.newSingleThreadExecutor();
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 3, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
        MyThread thread = new MyThread();
        Future<Integer> submit1 = executor.submit(thread);
        Future<Integer> submit = service.submit(thread);
        try {
            System.out.println("自定义线程池的方式"+submit1.get());
            System.out.println("线程池工具类的方式"+submit.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        service.shutdown();
        executor.shutdown();
    }

    static class MyThread implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            return 15;
        }
    }
}
